package com.i18n.moka;

public class BracketProcessor {
    public static String processString(String input) {
        StringBuilder result = new StringBuilder();
        boolean skip = false;
        boolean insideBrackets = false;
        
        for (int i = 0; i < input.length(); i++) {
            char c = input.charAt(i);
            if (c == '(') {
                insideBrackets = true;
                skip = false;
                result.append(c);
            } else if (c == ')') {
                if (insideBrackets && result.length() > 0 && result.charAt(result.length() - 1) == '(') {
                    skip = true;
                    result.setLength(result.length() - 1);  // Remove the (
                } else {
                    result.append(c);
                }
                insideBrackets = false;
            } else {
                if (!skip) {
                    result.append(c);
                }
            }
        }
        // Remove all brackets from the final result
        return result.toString().replaceAll("[()]", "");
    }

    public static void main(String[] args) {
        String input = "2025()，";
        String output = processString(input);
        System.out.println(output);  // 输出: 2025
    }
}
